/**
 * Created by wrl on 2017/7/13.
 */
$(function(){
    $(document).keyup(function (e) {
        if(e.which==13){
            $('#selectBtnEnter').click();
        }
    })
});
var path = '../';
var pagePath = path+'personInfo/selectPaging';
Vue.http.options.emulateJSON = true;
var vue = new Vue({
    el: '#show-user-list',
    data:{
        pageInfo:{},
        searchData:{
            page:1,
            rows:10,
            phoneNum:null,
            param1:null,
            isSearch:'0'
        },
        ids:[],
        permissions:{},//权限
        showPage:5      /*显示页码个数*/
    },
    mounted:function(){
        var self = this;
        self.$http.get(pagePath,{}).then(function(res){
            self.pageInfo = res.body.pagination;

            //分页
            customUtils.paging("#pagination",self.pageInfo.pages,self.showPage,function(num) {
                currentPage = num;
                if(num == self.searchData.page)
                    return;
                self.searchData.page = num;
                self.$http.post(pagePath,self.searchData).then(function(res){
                    self.pageInfo = res.body.pagination;
                })
            })
        },function(res){
            console.log(res.body)
            console.log('请求失败');
        });
      //遍历权限
  	  $.each(parent.globalPermissions, function(i,val) {
  		  self.$data.permissions[val.replace(':','_')]=true;
  	  });
    },
    filters: {
        timeF: function(time) {
            return $.fn.dateFormat(time,'yyyy-MM-dd')
        }
    },
    methods:{
        cbBtn:function(e){
            this.ids.push($(e.target).val())
        },
        search:function(){
            var self = this
            self.searchData.isSearch = '1'
            self.$http.post(pagePath,self.searchData).then(function(res){
                self.pageInfo = res.body.pagination;
                //分页
                customUtils.paging("#pagination",self.pageInfo.pages,self.showPage,function(num) {
                    currentPage = num;
                    if(num == self.searchData.page)
                        return;
                    self.searchData.page = num;
                    self.$http.post(pagePath,self.searchData).then(function(res){
                        self.pageInfo = res.body.pagination;
                    })
                })
            },function(res){
                console.log(res.body)
                console.log('请求失败');
            })
        },
        change_password:function(id){
            layer_show('修改密码','change-password.html?id='+id,'650','400')
        },
        admin_list_add:function(){
            layer_show('添加用户','admin-list-add-update.html','800','500')
        },
        admin_list_edit:function(id){
            layer_show('修改用户信息','admin-list-add-update.html?action=update&updateId='+id,'800','500')
        },
        startORlock:function(id,status){
            var self = this;
            self.$http.post(path+'personInfo/startORlock',{
                status:status,
                id:id
            }).then(function(res){
                if(res.body.flag == true){
                    tips('操作成功！',6)
                    setTimeout(function(){
                        location.replace(location.href);
                    },500);
                }else{
                    tips('操作失败！',5)
                }
            },function(res){
                tips('请求失败！',5)
            })
        },
        del:function(id){
            var self = this;
            layer.confirm('用户删除须谨慎，确认要删除吗？', function(data) {
                self.$http.post(path + 'personInfo/deleteById',{'id':id}).then(function (res) {
                    if (res.body.flag == true) {
                        tips('删除成功！', 6)
                        setTimeout(function () {
                            location.replace(location.href);
                        }, 500);
                    } else {
                        tips('删除失败！', 5)
                    }
                }, function (res) {
                    tips('请求失败！', 5)
                })
            })
        },
        dels:function(){
            //批量删除
            var self = this;
            if(self.ids.length != 0){
                layer.confirm('确认删除？',function(data){
                    self.$http.get(path+'personInfo/deleteByIds?ids='+self.ids,{}).then(function(response){
                        if(response.body.flag){
                            tips('操作成功',6)
                            setTimeout(function(){
                                location.replace(location.href);
                            },500)
                        }else{
                            tips('删除失败',5)
                        }
                    },function(response){
                        console.log(response.body)
                        tips('操作失败',5)
                    })
                })
            }else{
                tips('请选择需要删除的功能',5)
            }
        }
    }
});
